//
//  File.swift
//  MasterBoy
//
//  Created by kyson on 2024/9/20.
//

import Foundation
import YYText


class MBDGroupNameCellModel : MBDGroupDetailCommonCellModel {
    var groupNameTextLayout : YYTextLayout?
    
    static let MarginTop : CGFloat = 15
    static let MarginBottom : CGFloat = 15
    static let MarginNameLabelLeftAndRight : CGFloat = 7

    override var groupDetail: MBDGroupDetailModel! {
        didSet {
            let groupInfo = self.groupDetail.groupName!
            let groupDetailAttributeString = NSMutableAttributedString(string: groupInfo )
            groupDetailAttributeString.yy_font = UIFont.boldSystemFont(ofSize: 20)
            groupDetailAttributeString.yy_lineSpacing = 4
//            groupDetailAttributeString.yy_alignment = .center

            groupDetailAttributeString.setDynamicTextColor()
            
            let groupDetailContainer = YYTextContainer()
            
            let groupDetailWidth = CGRectGetWidth(UIScreen.main.bounds) - MBDGroupNameCellModel.MarginLeftAndRightBackgroundView * 2 - MBDGroupNameCellModel.MarginNameLabelLeftAndRight * 2
            groupDetailContainer.size = CGSizeMake(groupDetailWidth , CGFLOAT_MAX)
            let groupDetailLayout = YYTextLayout(container: groupDetailContainer, text: groupDetailAttributeString)
            
            self.groupNameTextLayout = groupDetailLayout
        }
    }
    
    override func cellHeight() -> CGFloat {
        return MBDGroupNameCellModel.MarginTop + (self.groupNameTextLayout?.textBoundingSize.height ?? 0) + MBDGroupNameCellModel.MarginBottom
    }
}
